from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-04 14:05:36.913324
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 04, May, 2021
Time: 14:05:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9913
Nobs: 281.000 HQIC: -48.6892
Log likelihood: 3408.00 FPE: 4.48426e-22
AIC: -49.1566 Det(Omega_mle): 3.27349e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.414839 0.118904 3.489 0.000
L1.Burgenland 0.068776 0.059442 1.157 0.247
L1.Kärnten -0.224978 0.052869 -4.255 0.000
L1.Niederösterreich 0.098881 0.127911 0.773 0.439
L1.Oberösterreich 0.223536 0.123592 1.809 0.071
L1.Salzburg 0.273222 0.068152 4.009 0.000
L1.Steiermark 0.111359 0.086705 1.284 0.199
L1.Tirol 0.119452 0.060119 1.987 0.047
L1.Vorarlberg -0.033071 0.055132 -0.600 0.549
L1.Wien -0.043214 0.110984 -0.389 0.697
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.441004 0.137217 3.214 0.001
L1.Burgenland 0.002935 0.068597 0.043 0.966
L1.Kärnten 0.329866 0.061011 5.407 0.000
L1.Niederösterreich 0.111632 0.147611 0.756 0.449
L1.Oberösterreich -0.066041 0.142626 -0.463 0.643
L1.Salzburg 0.222878 0.078649 2.834 0.005
L1.Steiermark 0.090553 0.100059 0.905 0.365
L1.Tirol 0.136773 0.069379 1.971 0.049
L1.Vorarlberg 0.151799 0.063623 2.386 0.017
L1.Wien -0.411837 0.128077 -3.216 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.261927 0.060321 4.342 0.000
L1.Burgenland 0.104416 0.030156 3.463 0.001
L1.Kärnten -0.013028 0.026821 -0.486 0.627
L1.Niederösterreich 0.086801 0.064890 1.338 0.181
L1.Oberösterreich 0.286378 0.062699 4.567 0.000
L1.Salzburg 0.017393 0.034574 0.503 0.615
L1.Steiermark -0.000269 0.043986 -0.006 0.995
L1.Tirol 0.068001 0.030499 2.230 0.026
L1.Vorarlberg 0.075660 0.027969 2.705 0.007
L1.Wien 0.114819 0.056303 2.039 0.041
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.210429 0.057695 3.647 0.000
L1.Burgenland 0.028120 0.028843 0.975 0.330
L1.Kärnten 0.009184 0.025653 0.358 0.720
L1.Niederösterreich 0.055597 0.062065 0.896 0.370
L1.Oberösterreich 0.394516 0.059969 6.579 0.000
L1.Salzburg 0.080818 0.033069 2.444 0.015
L1.Steiermark 0.132594 0.042071 3.152 0.002
L1.Tirol 0.050302 0.029171 1.724 0.085
L1.Vorarlberg 0.081008 0.026751 3.028 0.002
L1.Wien -0.043216 0.053852 -0.802 0.422
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.462135 0.113052 4.088 0.000
L1.Burgenland 0.101216 0.056517 1.791 0.073
L1.Kärnten 0.009842 0.050267 0.196 0.845
L1.Niederösterreich 0.015213 0.121615 0.125 0.900
L1.Oberösterreich 0.123698 0.117508 1.053 0.292
L1.Salzburg 0.054689 0.064798 0.844 0.399
L1.Steiermark 0.068836 0.082437 0.835 0.404
L1.Tirol 0.202092 0.057160 3.536 0.000
L1.Vorarlberg 0.035902 0.052419 0.685 0.493
L1.Wien -0.067697 0.105521 -0.642 0.521
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209699 0.089063 2.355 0.019
L1.Burgenland -0.012220 0.044524 -0.274 0.784
L1.Kärnten -0.006737 0.039600 -0.170 0.865
L1.Niederösterreich -0.013734 0.095809 -0.143 0.886
L1.Oberösterreich 0.415968 0.092574 4.493 0.000
L1.Salzburg 0.013915 0.051048 0.273 0.785
L1.Steiermark -0.026459 0.064944 -0.407 0.684
L1.Tirol 0.161256 0.045031 3.581 0.000
L1.Vorarlberg 0.057729 0.041296 1.398 0.162
L1.Wien 0.206261 0.083130 2.481 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218693 0.108011 2.025 0.043
L1.Burgenland 0.020715 0.053996 0.384 0.701
L1.Kärnten -0.071517 0.048025 -1.489 0.136
L1.Niederösterreich -0.062726 0.116192 -0.540 0.589
L1.Oberösterreich 0.019651 0.112269 0.175 0.861
L1.Salzburg 0.082767 0.061908 1.337 0.181
L1.Steiermark 0.324115 0.078761 4.115 0.000
L1.Tirol 0.461195 0.054611 8.445 0.000
L1.Vorarlberg 0.145212 0.050081 2.900 0.004
L1.Wien -0.135090 0.100816 -1.340 0.180
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208999 0.129192 1.618 0.106
L1.Burgenland 0.040129 0.064585 0.621 0.534
L1.Kärnten -0.074075 0.057443 -1.290 0.197
L1.Niederösterreich 0.113197 0.138978 0.814 0.415
L1.Oberösterreich 0.015946 0.134285 0.119 0.905
L1.Salzburg 0.191461 0.074049 2.586 0.010
L1.Steiermark 0.131254 0.094207 1.393 0.164
L1.Tirol 0.055807 0.065321 0.854 0.393
L1.Vorarlberg 0.106422 0.059902 1.777 0.076
L1.Wien 0.218923 0.120586 1.815 0.069
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.526548 0.071454 7.369 0.000
L1.Burgenland -0.015005 0.035721 -0.420 0.674
L1.Kärnten -0.016322 0.031771 -0.514 0.607
L1.Niederösterreich 0.097836 0.076866 1.273 0.203
L1.Oberösterreich 0.309255 0.074271 4.164 0.000
L1.Salzburg 0.015946 0.040955 0.389 0.697
L1.Steiermark -0.044004 0.052104 -0.845 0.398
L1.Tirol 0.080071 0.036128 2.216 0.027
L1.Vorarlberg 0.102698 0.033131 3.100 0.002
L1.Wien -0.053417 0.066694 -0.801 0.423
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.160222 0.091644 0.167130 0.218771 0.078111 0.085909 0.000361 0.162320
Kärnten 0.160222 1.000000 0.053079 0.212921 0.184627 -0.065162 0.176458 0.020313 0.305061
Niederösterreich 0.091644 0.053079 1.000000 0.244393 0.092643 0.320954 0.146319 0.023863 0.314770
Oberösterreich 0.167130 0.212921 0.244393 1.000000 0.301773 0.259486 0.102371 0.061958 0.140708
Salzburg 0.218771 0.184627 0.092643 0.301773 1.000000 0.150695 0.063756 0.089697 0.021281
Steiermark 0.078111 -0.065162 0.320954 0.259486 0.150695 1.000000 0.095436 0.101002 -0.099206
Tirol 0.085909 0.176458 0.146319 0.102371 0.063756 0.095436 1.000000 0.151659 0.154909
Vorarlberg 0.000361 0.020313 0.023863 0.061958 0.089697 0.101002 0.151659 1.000000 -0.010861
Wien 0.162320 0.305061 0.314770 0.140708 0.021281 -0.099206 0.154909 -0.010861 1.000000